/**
 * @param {string[]} strs
 * @return {string}
 */
var longestCommonPrefix = function(strs) {
    let res='';
    let prefix=strs.reduce((pre,cur)=>cur.length<pre.length?cur:pre,strs[0])
    for (let index = 0; index < prefix.length; index++) {
        if(strs.every(x=>x[index]===prefix[index])){
            res+=prefix[index]
        }else{
            return res;
        }
        
    }
    return res;
};


let strs = ["flower","flow","flight"]

console.log(longestCommonPrefix(strs))